<?php
namespace Home\Controller;
use Think\Controller;
class WechatextraController extends BaseController {
	/*
	 * 获取用户信息
	 */
	public function getuserinfo(){
		$options = C('WECHAT_OPTIONS');
		$wechatObj = new \Org\WechatTest\WechatTest($options);

		//获取所有用户openid列表
		$openid_arr = $wechatObj->getwxuserlist();

		//获取用户信息
		$userlist = array();
		foreach($openid_arr as $v){
			$info = $wechatObj->getwxuserinfo($v);
			if($info){
				$userModel = M('user');
				$data = array(
					'openid' => $v,
					'nickname' => $info->nickname,
					'sex' => $info->sex,
					'subscribe' => $info->subscribe,
					'city' => $info->city,
					'country' => $info->country,
					'province' => $info->province,
					'language' => $info->language,
					'headimgurl' => $info->headimgurl,
					'subscribe_time' => $info->subscribe_time,
					'unionid' => $info->unionid,
					'remark' => $info->remark,
					'groupid' => $info->groupid,
				);
				$wheredata['openid'] = $v;

				$user_info = $userModel->where($wheredata)->find();
				if($user_info){
					$data['updatetime'] = date('Y-m-d H:i:s',time());
					$userModel->where($wheredata)->save($data);
				}else{
					$data['createtime'] = date('Y-m-d H:i:s',time());
					$userModel->add($data);
				}
				$userlist[] = $info;
			}

		}
		echo '<pre/>';
		print_r($userlist);
	}

	/*
	 * 签名
	 * ad7fea24cef804799ade2b754f4bcaed365665cc
	 */
	public function createsign(){
		$options = C('WECHAT_OPTIONS');
		$wechatObj = new \Org\WechatTest\WechatTest($options);
		$info = $wechatObj->getSignPackage();
		echo '<pre>';
		print_r($info);
		exit;
	}
}